package com.ljs.threadpooldemo.controller;

import com.ljs.threadpooldemo.entity.XmlEntity;
import com.ljs.threadpooldemo.entity.response.XmlEntityResponse;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * xml作为请求参数
 */
@RestController
public class XmlController {
    /**
     * produces 请求参数为xml,produces返回数据的格式MediaType.APPLICATION_JSON_VALUE ,这个是返回json,APPLICATION_ATOM_XML_VALUE 这个是返回xml
     * @param xmlEntity
     * @return
     */
    @PostMapping(value = "/getXml",produces = MediaType.APPLICATION_ATOM_XML_VALUE)
    public XmlEntityResponse getXml(@RequestBody XmlEntity xmlEntity){
        XmlEntityResponse xmlEntityResponse=new XmlEntityResponse();
        xmlEntityResponse.setId(xmlEntity.getId());
        xmlEntityResponse.setName(xmlEntity.getName());
        return  xmlEntityResponse;
    }
    @PostMapping(value = "/getJson",produces = MediaType.APPLICATION_JSON_VALUE)
    public XmlEntityResponse getJson(@RequestBody XmlEntity xmlEntity){
        XmlEntityResponse xmlEntityResponse=new XmlEntityResponse();
        xmlEntityResponse.setId(xmlEntity.getId());
        xmlEntityResponse.setName(xmlEntity.getName());
        return  xmlEntityResponse;
    }
}
